﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pixels.Extensions;
using Pixels.Core;
using System.Linq.Expressions;

namespace Pixels.Cms.Core
{
    [PixelContentType("Page", "Page Content Type")]
    public class Page : Pixels.ListItems.ListItem, IVersionable, ICommentable, IPublishable, ITaggable
    {
        [PixelContentTypeItem("Content", 50)]
        public string BodyText
        {
            get;
            set;
        }

        [PixelContentTypeItem("Publish", 0)]
        public Publish Publish
        {
            get;
            set;
        }

        [PixelContentTypeItem("ChangeNote", 0)]
        public string ChangeNote
        {
            get;
            set;
        }

        [PixelContentTypeItem("AllowComments", 0)]
        public bool AllowComments
        {
            get;
            set;
        }

        [PixelContentTypeItem("Tag", 0)]
        public List<string> Tags
        {
            get;
            set;
        }

        public static Page FindByName(string Name)
        {
            return PixelsHelper.FetchListItem<Page>(p => p.Title == Name).FirstOrDefault();
        }

        public static List<Page> Find(Expression<Func<Page, bool>> expression)
        {
            return PixelsHelper.FetchListItem<Page>(expression);
        }

        public void Save()
        {
            PixelsHelper.SaveListItem<Page>(this);
        }
    }
}
